/************************************************************************
 * @file AbstractToolBarManager.cpp
 * @author Ian Chen
 * @version 1.0
 *
 * @section LICENSE
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details at
 * http://www.gnu.org/licenses/lgpl.html
 *
 ************************************************************************/
#include <pluginui/manager/AbstractToolBarManager.h>

namespace antu
{
namespace plugin
{
namespace ui
{
AbstractToolBarManager::AbstractToolBarManager()
{
}

AbstractToolBarManager::~AbstractToolBarManager()
{
    map<QString, AbstractToolBar*>::iterator iter = this->m_oToolBars.begin();
    map<QString, AbstractToolBar*>::iterator end = this->m_oToolBars.end();
    for (; iter != end; iter++)
    {
        delete iter->second;
    }
    this->m_oToolBars.clear();
}

AbstractToolBar *AbstractToolBarManager::toolBar(const QString &name)
{
    map<QString, AbstractToolBar*>::iterator iter = this->m_oToolBars.find(name);

    if (iter == this->m_oToolBars.end())
    {
        AbstractToolBar* pToolBar = this->createToolBar(name);
        this->m_oToolBars.insert(pair<QString, AbstractToolBar*>(name, pToolBar));
        iter = this->m_oToolBars.find(name);
    }
    return iter->second;
}

AbstractToolBar::AbstractToolBar(QWidget *pWidget)
    : m_pWidget(pWidget)
{
    Q_ASSERT(m_pWidget != nullptr);
}

AbstractToolBar::~AbstractToolBar()
{
    if (m_pWidget->parent() == nullptr)
        delete m_pWidget;
}

void AbstractToolBar::addWidget(QWidget *pWidget, int stretch)
{
    Q_ASSERT(pWidget != nullptr);
    pWidget->setParent(this->m_pWidget);
    this->appendWidget(pWidget, stretch);
}

}
}
}

